package main

import (
	"bytes"
	"fmt"
	"math"
)

var minCount = math.MaxInt32

func main() {
	var n int
	var s string
	var arr []int

	_, _ = fmt.Scan(&n)
	_, _ = fmt.Scan(&s)
	arr = make([]int, 2*n)
	for i := 0; i < 2*n; i++ {
		_, _ = fmt.Scan(&arr[i])
	}

	bs := []byte(s)
	flag := map[string]int{
		makeKey(arr, bs): 0,
	}
	f(0, arr, []byte(s), flag)
	fmt.Println(minCount)
}

func f(count int, arr []int, bs []byte, flag map[string]int) {
	if count < minCount {
		if check(arr, bs) {
			minCount = count
			return
		}

		for i := 1; i < len(bs); i++ {
			arr[i-1], arr[i] = arr[i], arr[i-1]
			bs[i-1], bs[i] = bs[i], bs[i-1]

			if _, ok := flag[makeKey(arr, bs)]; !ok || count+1 < flag[makeKey(arr, bs)] {
				flag[makeKey(arr, bs)] = count + 1
				f(count+1, arr, bs, flag)
			}

			arr[i-1], arr[i] = arr[i], arr[i-1]
			bs[i-1], bs[i] = bs[i], bs[i-1]
		}
	}
}

func check(arr []int, bs []byte) bool {
	pb, pr := 0, 0

	for i := 0; i < len(bs); i++ {
		if bs[i] == 'B' {
			if arr[i] < pb {
				return false
			}
			pb = arr[i]
		} else {
			if arr[i] < pr {
				return false
			}
			pr = arr[i]
		}
	}

	return true
}

func makeKey(arr []int, bs []byte) string {
	bf := bytes.NewBufferString(string(bs))
	for _, v := range arr {
		bf.WriteByte(byte('0' + v))
		bf.WriteByte(',')
	}

	return bf.String()
}
